import 'package:floor/floor.dart';
import 'package:share_fit/app/dao/dao_mixin.dart';
import 'package:share_fit/app/models/home/step_model.dart';

@dao
abstract class StepDao with DaoMixin<StepModel> {
  @override
  @Query('SELECT * FROM step WHERE _id = :id')
  Stream<StepModel?> findById(int id);

  @override
  @Query('SELECT * FROM step')
  Future<List<StepModel>> findAll();

  @Query('select sum(step) as step, sum(calories) as calories, sum(distance) as distance , max(end_time) as end_time, max(end_time) as start_time '
      'from step where address = :address and calendar = :calender')
  Future<StepModel?> findTodaySummary(String address, String calender);

  @Query('select sum(step) as step, sum(calories) as calories, sum(distance) as distance '
      'from step '
      'where address = :address and calendar >= :calenderStart and calendar <= :calendarEnd')
  Future<StepModel?> findForReport(String address, String calenderStart, String calendarEnd);

  @override
  @Query('SELECT * FROM step')
  Stream<List<StepModel>> findAllAsStream();

  @override
  @Query('delete FROM step')
  Future<void> deleteAll();

  @Query('SELECT * FROM step WHERE date_created >= :startTime and date_created < :endTime')
  Future<List<StepModel>> findBy(int startTime, int endTime);

  @Query('delete FROM step where address = :address')
  @override
  Future<void> deleteAllByAddress(String address);
}
